/// @tags:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

int main() {
  int n;
  cin >> n;
  int max1 = 0, max2 = 0, max3 = 0;
  for (int i = 1; i <= n; ++i) {
    int a;
    cin >> a;
    if (a >= max1) {
      max3 = max2, max2 = max1, max1 = a;
    } else if (a >= max2) {
      max3 = max2, max2 = a;
    } else if (a > max3) {
      max3 = a;
    }
  }
  std::string one = std::to_string(max1);
  std::string two = std::to_string(max2);
  std::string three = std::to_string(max3);
  std::string ans = one + two + three;
  ans = std::max(ans, one + three + two);
  ans = std::max(ans, two + three + one);
  ans = std::max(ans, two + one + three);
  ans = std::max(ans, three + two + one);
  ans = std::max(ans, three + one + two);
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("A.in", "r", stdin);
  freopen("A.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
